class AIFactory:
    """AI工具工厂类"""

    def __init__(self):
        self.config = AIConfig()
        self.proxy = ModelProxy(self.config)
        self.image_gen = ImageGenerator(self.config)
        self.video_model = VideoModel(self.config)
        self.voice_model = VoiceModel(self.config)

    def create_conversation(self, model: str = "gpt-4"):
        """创建对话会话"""
        return ConversationSession(self.proxy, model)

    def batch_process_images(self, prompts: List[str]):
        """批量处理图片生成"""
        results = []
        for prompt in prompts:
            try:
                result = self.image_gen.generate_with_dalle(prompt)
                results.append(result)
            except Exception as e:
                results.append(None)
                print(f"生成失败: {prompt}, 错误: {e}")
        return results


class ConversationSession:
    """对话会话管理"""

    def __init__(self, proxy: ModelProxy, model: str):
        self.proxy = proxy
        self.model = model
        self.history = []

    def send_message(self, message: str, **kwargs):
        """发送消息并获取回复"""
        self.history.append({"role": "user", "content": message})

        response = self.proxy.chat_completion(
            self.model,
            self.history,
            **kwargs
        )

        assistant_reply = response.choices[0].message.content
        self.history.append({"role": "assistant", "content": assistant_reply})

        return assistant_reply